package com.manong.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.manong.dao.ActionLogMapper;
import com.manong.entity.ActionLog;
import com.manong.service.ActionLogService;
import com.manong.vo.query.ActionLogVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
@Service
public class ActionLogServiceImpl extends ServiceImpl<ActionLogMapper, ActionLog> implements ActionLogService {

    /**
     * 分页查询操作日志
     * @param actionLogVo
     * @return
     */
    @Override
    public IPage<ActionLog> findActionListByUsername(IPage<ActionLog> page, ActionLogVo actionLogVo) {
        QueryWrapper<ActionLog> queryWrapper = new QueryWrapper<ActionLog>();
        queryWrapper.like(!ObjectUtils.isEmpty(actionLogVo.getUsername()),"username",actionLogVo.getUsername())
                    .orderByDesc("action_time");
        return baseMapper.selectPage(page,queryWrapper);
    }

    /**
     * 批量删除操作日志
     * @param ids
     * @return
     */
    @Override
    public boolean delete(List<Long> ids) {
        if(baseMapper.deleteAction(ids)>0){
            return true;
        }
        return false;
    }
}
